﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using blackhouse.Web.FasterFiles;

namespace blackhouse.Web {
    /// <summary>
    /// Summary description for CssFiles
    /// </summary>
    public class ClientFiles : IHttpHandler {

        public void ProcessRequest(HttpContext context) {
            try {

                string type = context.Request["type"];
                string client = context.Request["id"];
                if (string.IsNullOrEmpty(type)) return;
                if (string.IsNullOrEmpty(client)) return;

                if (type == "css") {
                    context.Response.Clear();
                    context.Response.ContentType = "text/css";
                    context.Response.Charset = "utf-8";
                    FasterFilesProvider provider = new FasterFilesProvider();
                    provider.GetCssContent(client, context.Response);
                }
                if (type == "js") {
                    context.Response.Clear();
                    context.Response.Charset = "utf-8";
                    context.Response.ContentType = "application/x-javascript";

                    FasterFilesProvider provider = new FasterFilesProvider();
                    provider.GetJsContent(client, context.Response);
                }

            } catch (Exception e) {
                context.Response.Write(e);
            }
            //string hash = context.Request["cssid"];

            //if (!string.IsNullOrEmpty(hash))
            //{
            //    context.Response.Clear();
            //    context.Response.ContentType = "text/css";
            //    FasterFilesProvider.GetCssContent(hash, context.Response.OutputStream);
            //    context.Response.End();
            //    return;
            //}
            //hash = context.Request["jsid"];
            //if (!string.IsNullOrEmpty(hash))
            //{
            //    context.Response.Clear();
            //    context.Response.ContentType = "text/javascript";
            //    FasterFilesProvider.GetJsContent(hash, context.Response.OutputStream);
            //}
        }

        public bool IsReusable {
            get {
                return false;
            }
        }
    }
}